import {
  mapGetters
} from 'vuex'
export default {
  data() {
    return {
      test: 999
    }
  },
  methods: {},
  computed: {
    ...mapGetters('cart', ['total'])
  },
  onShow() {
    uni.setTabBarBadge({
      "index": 2,
      "text": this.total + ''
    })
  },
  watch: {
    total: {
      handler(newVal) {
        const pageArr = ['pages/home/home', 'pages/cate/cate', 'pages/cart/cart', 'pages/my/my']
        const current = getCurrentPages()
        console.log('current', current);
        // h5  current=[]
        if (current.length) {
          const len = current.length - 1
          if (pageArr.includes(current[len].route)) {
            // console.log('current', current);
            // setTabBarBadge只能在tabbar页面执行
            uni.setTabBarBadge({
              "index": 2,
              "text": newVal + ''
            })
          }
        }
      },
      immediate: true
    }
  },
  filters: {}
}